﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agile.Manager.Windows.Model;

namespace Agile.Manager.SQLite.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            SQLiteDataManagement sql = new SQLiteDataManagement();
            Task t = new Task();
            t.ID = Guid.NewGuid().ToString();
            t.Name = "testing parent task";

            string id = string.Empty;

            Console.WriteLine("Populating Data....");
            for (int i = 0; i < 3; i++)
            {
                Task subt = new Task();
                subt.ID = Guid.NewGuid().ToString();
                subt.Name = "subtask" + i.ToString();
                subt.TaskID = t.ID;
                t.Subtasks.Add(subt);
            }

            Console.WriteLine("Saving new Data....");
            sql.Save<Task>(t);

            foreach (Task item in t.Subtasks)
            {
                sql.Save<Task>(item);
            }

            Console.WriteLine("Saving Repeated Data.....");
            Task trepeated = new Task();
            trepeated.ID = t.ID;
            trepeated.Name = "testing reapeated task";
            sql.Save<Task>(trepeated);

            Console.WriteLine("Result Data....");
            List<Task> tasks = sql.GetData<Task>();

            foreach (Task item in tasks)
            {
                Console.WriteLine("Task ID:" + item.ID);
                Console.WriteLine("Task Name:" + item.Name);
                Console.WriteLine("Task ParentTaskID:" + item.TaskID);
                Console.WriteLine();
                id = item.ID;
            }


            Console.WriteLine("Testing deleting Data.....");
            Task deleteTask = new Task();
            deleteTask.ID = id;
            sql.Delete<Task>(deleteTask);
            Console.WriteLine("Result Data....");
            tasks = sql.GetData<Task>();

            foreach (Task item in tasks)
            {
                Console.WriteLine("Task ID:" + item.ID);
                Console.WriteLine("Task Name:" + item.Name);
                Console.WriteLine("Task ParentTaskID:" + item.TaskID);
                Console.WriteLine();
            }
            Console.Read();
        }
    }
}
